<?php 
require_once $_SERVER['DOCUMENT_ROOT'].'/inc/core/env.inc.php';

$return["success"] = false;
$return["html"] = null;
$return["jscript"] = null;
$return["error"] = null;

if ($_USER->asPermission('set_permissions')) {
		
	if (	(strpos("mod_", $_POST["name"]) == 0 || strpos("set_", $_POST["name"]) == 0 || strpos("del_", $_POST["name"]) == 0)
		&&	($_POST["description"] == "{VOCABULARY|permission_".$_POST["name"]."}") ) {
		
		$name = $_POST["name"];
		$description = "{VOCABULARY|permission_".$_POST["name"]."}";
		
		//create chiamata sql 
		$sql = "INSERT INTO ".$_DB->getPrefix()."permissions (name, description) VALUES ('".$name."', '".$description."')";
		$res = $_DB->query($sql);
		
		if ($res) {
			$return["success"] = true;
			$return["error"] = '';
			$return["jscript"] = 'loadAddPermissions()';
		} else {
			$return["error"] = 'Error query insert';
		}
		
	} else {
		$return["error"] = 'Error invalid name or description.';
	}

} else {
	$return["error"] = 'Error not create permission.';
}

echo '('.json_encode($return).')';
?>